<?php
// Directory separator shorten
if(!defined('DS')) {
	define('DS', DIRECTORY_SEPARATOR);
}

// Project root
if(!defined('PROJECT_ROOT')) {
	define('PROJECT_ROOT', realpath(dirname(dirname(__FILE__))));
}

// Application path
if(!defined('APPLICATION_PATH')) {
	define('APPLICATION_PATH', PROJECT_ROOT . DS . 'application');
}

// Application environment
if(!defined('APPLICATION_ENV')) {
	define('APPLICATION_ENV',
		(getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
}

// Include paths
set_include_path(implode(PATH_SEPARATOR, 
	array(PROJECT_ROOT . DS . 'library', PROJECT_ROOT . DS . 'library' .DS . 'Rest', get_include_path())));

// Zend_Application
require_once 'Zend/Application.php';

// Zend_Registry
require_once 'Zend/Registry.php';

// Zend_Registry
require_once 'Zend/Config.php';

// Create application
$app = new Zend_Application(
	APPLICATION_ENV,
	APPLICATION_PATH . DS . 'configs' . DS . 'application.ini'
);

// Throw warnings when development and testing
if ('production' !== APPLICATION_ENV) {
	$app->getAutoloader()->suppressNotFoundWarnings(false);
}

$config = new Zend_Config($app->getOptions());
Zend_Registry::set('config', $config);

$db = Zend_Db::factory($config->resources->db);
Zend_Db_Table::setDefaultAdapter($db);

// Bootstrap (only) frontController and run
$app->getBootstrap()->bootstrap('FrontController')->run();

?>